package com.docMan.utils;

import java.util.Iterator;

import com.docMan.dao.pojo.DocDirectory;
import com.docMan.dao.pojo.DocDisc;
import com.docMan.service.DocDirectoryService;
import com.docMan.service.DocDiscService;

public class GetRealPath {
	private static DocDiscService docDiscService=(DocDiscService) SpringContextUtils.getObject("docDiscService");
	private static DocDirectoryService docDirectoryService=(DocDirectoryService) SpringContextUtils.getObject("docDirectoryService");
	/**
	 * 
	 * @param pathId 1/2/3/4/5 文件或文件夹的路劲，第一个数字是disk 也就是网盘的id后面的都是文件夹的id，根据这些id获取文件的真实路径  信息中心/潘善亮的个人文件夹/2014年工作总结
	 * @return
	 */
	public static String getPath(String pathId){
		String[] ids= pathId.split("/");
		StringBuilder realPath=new StringBuilder();
		for (int i = 0; i < ids.length; i++) {
			if(i==0){
				DocDisc docDisc=docDiscService.getById(Integer.parseInt(ids[i]));
				realPath.append(docDisc.getName());
			}else{
				DocDirectory docDirectory=docDirectoryService.getById(Integer.parseInt(ids[i]));
				realPath.append("/");
				realPath.append(docDirectory.getName());
			}
		}
		return realPath.toString();
	}
	/**
	 * 在上传文件时获取文件的所在的路径
	 * @param docDirectoryId
	 * @return
	 */
	public static String getPathIds(int docDirectoryId){
		DocDirectory docDirectory=docDirectoryService.getById(docDirectoryId);
		
		return docDirectory.getPath()+FinalConfig.path_split+docDirectoryId;
	}
	/**
	 * 获取文件夹的全路径
	 * @param docDirectoryId
	 * @return
	 */
	public static String getDirPath(int docDirectoryId){
		DocDirectory docDirectory=docDirectoryService.getById(docDirectoryId);
		String pathId=docDirectory.getPath()+FinalConfig.path_split+docDirectoryId;
		String[] ids= pathId.split("/");
		StringBuilder realPath=new StringBuilder();
		for (int i = 0; i < ids.length; i++) {
			if(i==0){
				DocDisc docDisc=docDiscService.getById(Integer.parseInt(ids[i]));
				realPath.append(docDisc.getName());
			}else{
				docDirectory=docDirectoryService.getById(Integer.parseInt(ids[i]));
				realPath.append("/");
				realPath.append(docDirectory.getName());
			}
		}
		
		return realPath.toString();
	}
}
